<template>
	<view class="main_bg">
		<app-headerIndex title="首页" :isBack="false"></app-headerIndex>
		<view class="account_bg">
			<view class="top">
				<view class="head flex-s">
					<view class="avatar flex-c">
						<u-avatar :src="userInfo.avatar" size="120rpx"></u-avatar>
						<view class="name flex-c">
							<view class="nickname">{{userInfo.name}}</view>
							<view class="company">{{userInfo.shop_name_f || ''}}</view>
						</view>
					</view>
					<view class="setting" @click="$func.toUrl('/pages/setting/setting')">
						<u-icon name="setting" size="36rpx"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view class="tools flex-c">
			<view class="tools_son flex-c" @click="scanCode(1)">
				<view class="name">扫码维修</view>
			</view>
			<view class="tools_son flex-c" @click="$func.atUrl('/pages_worker/repair/repair');getMsgId()">
				<view class="name">维修列表</view>
			</view>
			<view class="tools_son flex-c" @click="$func.atUrl('/pages_worker/inspection/inspection')">
				<view class="name">巡检</view>
			</view>
			<view class="tools_son flex-c" @click="scanCode(0)">
				<view class="name">扫码报修</view>
			</view>
			<!-- view class="tools_son flex-c" @click="$func.atUrl('/pages_worker/repair/simple?from_type=1');getMsgId()">
				<view class="name">简易维修列表</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {

			}
		},
		computed: {
			userInfo() {
				return this.$store.state.user.info
			}
		},
		created() {

		},
		methods: {
			// value 1 维修 0 报修
			scanCode(value) {
				uni.scanCode({
					success: (res) => {
						const data = decodeURIComponent(res.path)
						const arr = data.split('=')
						const deviceId = arr.length > 1 ? arr[arr.length - 1] : 0
						if (value === 0) {
							this.$func.toUrl('/pages_worker/repair/add?id=' + deviceId)
						} else {
							this.$func.toUrl('/pages_worker/index/index?device_id=' + deviceId)
						}
						// uni.showLoading({
						// 	title: "请稍等"
						// })
						// this.$http.post('/data/api.auth.User/deviceVier', { id: deviceId }).then(rest => {
						// 	uni.hideLoading()
						// 	if (rest.data.device_status == 3) {
						// 		this.$func.tips(rest.data.device_name + '已报废')
						// 	} else {
						// 		this.$func.toUrl('/pages_worker/index/index?device_id=' + deviceId)
						// 	}
						// }).catch(e => {
						// 	uni.hideLoading()
						// })
					}
				});
			},
			getMsgId() {
				this.$http.post('/data/api.auth.Msg/getMsgId').then(res => {
					uni.requestSubscribeMessage({
						tmplIds: res.data
					})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.account_bg {
		height: 110rpx;
		background-color: #4F6FF6;
		padding: 20rpx;

		.top {
			font-size: 36rpx;


			background: rgba(255, 255, 255, 1);

			border-radius: 10rpx;
			color: #333333;

			.head {
				padding: 44rpx 36rpx;

				.name {
					margin-left: 20rpx;
					flex-direction: column;
					align-items: flex-start;

					.company {
						// margin-top: 8rpx;
						font-size: 28rpx;
					}
				}


			}


		}
	}

	.tools {
		margin: 80rpx 20rpx 0;
		padding: 40rpx 0 0;
		border-radius: 10rpx;
		flex-wrap: wrap;
		justify-content: space-between;

		.tools_son {
			width: calc(50% - 12rpx);

			height: 178rpx;
			border-radius: 10rpx;
			background-color: #4FB3F6;
			color: #FFFFFF;
			font-size: 36rpx;
			margin-bottom: 24rpx;

			&:nth-child(2) {

				background-color: #F68C4F;

			}

			&:nth-child(3) {

				background-color: #4F6FF6;

			}

			&:nth-child(4) {
				background-color: #1F3BB3;

				.icon {
					background-color: #1F3BB3;
				}
			}

			&:nth-child(5) {
				background-color: #D90808;

				.icon {
					background-color: #D90808;
				}
			}

			&:nth-child(6) {
				background-color: #04BFA1;

				.icon {
					background-color: #04BFA1;
				}
			}

			&:nth-child(7) {
				background-color: #4F6FF6;

				.icon {
					background-color: #4F6FF6;
				}
			}
		}
	}

	.tools {
		button {
			background-color: rgba(255, 255, 255, 1);
			border: none;
			box-shadow: none;
			margin: 0;


			&::after {
				border: none;
			}
		}
	}
</style>